<!-- <template>
  <div class="card" style="width: 50%; padding: 20px">
    <el-form ref="formRef" :rules="User.rules" :model="User.form" label-width="80px" style="padding-right: 40px; padding-bottom: 20px;">
      <el-form-item label="账号" prop="username">
        <el-input v-model="User.form.username" autocomplete="off" placeholder="请输入账号" />
      </el-form-item>

      <el-form-item label="名称" prop="name">
        <el-input v-model="User.form.name" autocomplete="off" placeholder="请输入姓名" />
      </el-form-item>

      <el-form-item label="职位" prop="role">
        <el-input v-model="User.form.role" autocomplete="off" placeholder="请输入职位" />
      </el-form-item>

      <div style="text-align: center">
        <el-button @click="updateUser" type="primary" style="padding: 20px 30px;">更新个人信息</el-button>
      </div>
    </el-form>
  </div>
</template>

<script setup>
import { reactive, ref } from "vue"; 

const formRef = ref();
const User = reactive({
  form: {},
  rules: {
    username:[
      { required: true, message: '请输入账号', trigger: 'blur' }
    ],
    name:[
      { required: true, message: '请输入姓名', trigger: 'blur' }
    ],
    description:[
      { required: true, message: '请输入职位', trigger: 'blur' }
    ]
}
  })

</script> -->

<template>
  <div class="card" style="width: 50%; padding: 20px">
    <el-form ref="formRef" :rules="User.rules" :model="User.form" label-width="80px" style="padding-right: 40px; padding-bottom: 20px;">
      <el-form-item label="账号" prop="username">
        <el-input v-model="User.form.username" autocomplete="off" placeholder="请输入账号"></el-input>
      </el-form-item>

      <el-form-item label="名称" prop="name">
        <el-input v-model="User.form.name" autocomplete="off" placeholder="请输入姓名"></el-input>
      </el-form-item>

      <el-form-item label="职位" prop="role">
        <el-input v-model="User.form.role" autocomplete="off" placeholder="请输入职位"></el-input>
      </el-form-item>

      <div style="text-align: center">
        <el-button @click="updateUser" type="primary" style="padding: 10px 20px;">更新个人信息</el-button>
      </div>
    </el-form>
  </div>
</template>

<script setup>
import { reactive, ref } from "vue";
import axios from 'axios'; // 导入 axios
import { ElMessage } from 'element-plus'; // 确保已安装并导入 Element Plus 的消息组件

// 表单引用
const formRef = ref();

// 用户信息
const User = reactive({
  form: {
    username: '', // 初始化空值或默认值
    name: '',
    role: ''
  },
  rules: {
    username: [
      { required: true, message: '请输入账号', trigger: 'blur' }
    ],
    name: [
      { required: true, message: '请输入姓名', trigger: 'blur' }
    ],
    role: [ // 修改这里从 description 到 role
      { required: true, message: '请输入职位', trigger: 'blur' }
    ]
  }
});

// const emit = defineEmits(['updateUser'])
// const updateUser = () => {
//     request.put('/users/update', User.form).then(res => {
//       if (res.code === 200) {
//         ElMessage.success('更新成功');
//         localStorage.setItem('user', JSON.stringify(res.data))
//         emit('updateUser')
//       }
//     });
//   }
</script>